package com.feimaopian.controller;

import com.feimaopian.entity.Article;
import com.feimaopian.mapper.ArticleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    ArticleMapper articleMapper;

    @GetMapping("/findAll")
    public List<Article> findAll() {
        return articleMapper.findAll();
    }

    @PutMapping("/updateById")
    public boolean updateById(@RequestBody Article article){
        if(article==null){
            return false;
        }
        return articleMapper.updateById(article) == 1;
    }

    @PutMapping("/updateByTitle")
    public boolean updateByTitle(@RequestBody Article article){
        if(article==null){
            return false;
        }
        return articleMapper.updateByTitle(article) == 1;
    }
    @PostMapping("/add")
    public boolean addArticle(@RequestBody Article article){
        if(article==null){
            return false;
        }
        return articleMapper.addArticle(article) == 1;
    }

    @DeleteMapping("dele/{id}")
    public boolean deleById(@PathVariable Integer id) {
        if (id == null || id == 0) {
            return false;
        }
        return articleMapper.deleById(id) == 1;
    }
}
